/*
 *
 * @author  ACA
 *
 *
 * History:                                                                                 
 *          09, Sep 2004: the main class icaDB changed to portfolioMainScr.                 
 *          Backup_1                                                                        
 *                It has a functional JTextArea and a non functional MenuBar                
 *          Backup_2                                                                        
 *                The JTextArea is no longer there and the MenuBar is partialy functional   
 *          04, Oct 2004                                                                    
 *          Backup_5                                                                        
 *                First version with full qualified queries; next, integration of ICA, SVM. 
 *          12, Oct 2004                                                                    
 *                First packetized version of the program. main class changed name from:    
 *                portfolioMainScr to MainScr.                                              
 *          15, Oct 2004                                                                    
 *          Backup_8                                                                        
 *                Mask of the configure preprocess & ica screen finished (not functional).  
 *                Several bugs fixed: JTable can select multiple times and erase previous   
 *                values, the database selection query includes now shareVal as the third   
 *                column allways as target column.                                          
 *          08, Feb 2006                                                                    
 *                Begin overhaul to move mainScreen to Java5/Netbeans 5 fashion.            
 *          15, May 2006
 *                Major modifications on the look and feel of mainScreen, mainly addressing 
 *                a way to introduce a project, all of these in order to generalize the old 
 *                portfolio database as a real portfolio project.      
 *          30, Oct 2006
 *                The attributes and functions belonging to the handling of a project are
 *                beeing moved to a new class ProjectOpen.
 *          09, Apr 2007
 *                Estigia icon incorporated; several clases renamed in order to make them more
 *                aligned with the propose of the project.
 *          08, May 2007
 *                Windows look and feal feature moved from main method to MainScreen method.
 *          10, May 2007
 *                Method showInsertedStock eliminated, the last one from the old days, sigh!.
 *          03, Jun 2007
 *                LogOnDB class eliminated; the functionality was transfered into Host class.
 *          04, Jun 2007
 *                Initiated an overhaul of the code, included the elimination of some useless classes
 *                and the renaming of portfolioDB clases in order to state that this is a general
 *                prupose project.
 *          30, Jul 2007
 *                V 0.3.8 all overhead erased.
 *          09, Aug 2007
 *                V 0.3.9
 *          29, Aug 2007
 *                V 0.3.10
 *          05, Sep 2007
 *                V 0.3.11
 *          13, Sep 2007
 *                V 0.3.12
 *          26, May 2008 
 *                On SelectVariables and StockItems, in order to prevent more than one stock to be displaied, prevents 
 *                the creation of other instance of stockMenu. So, it seems that I did something during 2008.                
 *          08, Jan 2009
 *                V 0.3.13 program revamp, some code cleaning.
 *          13, February 2009
 *                this modification corrects a bug that prevents the correct updating of the DBTree
 *                area when a SQL script creates a new database.
 *                now the DBTree display area is updated and displayed upon creation of a database
 *          27, February 2009
 *                V 0.3.14 full programming works reestablished.
 *                This version includes improvementes on the new project handling window. The improvements
 *                allow flexible creation and deletion of projects.
 *                With this generation (V 0.4.x) finishes the improvements on the new project window ans starts the
 *                configuration of input variables and svm params for the SVM.
 *          03, March 2009
 *                V 0.3.15 and last of the V 0.3.x series
 *                this version corrects several bugs that prevent a correct behaviour with java v 1.6, the
 *                current java version as up to march 2009.
 *          04, March 2009
 *                V 0.4 first of the series.
 *                in order to have more flexibility handling experiments, this series of sources integrate the configuration 
 *                of stock variables (intrinsec and extrinsec) and SVM config to a project
 *          07, March 2009
 *                Version based on the code V 0.4 which is basicaly the same as V 0.3.15 with some bugs fixed and some code
 *                cleaning. From here onwards, both versions 0.4a & 0.4b will divert, and, eventually the improvements will be merged
 *                again into a single version v 0.5.
 *          20, March 2009
 *                Version v0.4a.01; the most visible change on this version is the elimination of the table tab; most important 
 *                 is the extensive cleaning of the code.
 *          23, March 2009
 *                Version v0.4a.02; some bugs corrected, improved displayMessage (not enough yet) and basic variables persistence.
 *          25, March 2009
 *                Version v0.4a.03; some bugs corrected, basic setup of the new table stockexperiments that will save info of experiments
 *                 and will allow to repeat them.
 *          28, March 2009 <LOST>
 *                Version v0.4a.04. Project handling improved, thar is, all the methods that performed project handling activities that were
 *                performen on the ProjectNew class are now moved to the Project class, and ProjectNew is now a user interface only.
 *          30, March 2009
 *                Version v0.4a.05. All the basic handling for the creation and retrieving of StockExperiments as a table of the Project
 *                database. This is a checkpoint version in order to allow a rollback procedure in case of problems with the renaming of
 *                the PrjNewTab class to ProjectTab class.
 *          01, April 2009
 *                Version v0.4a.06. First version that allows to save stock variables experiments and triger the stocksVariables screen, yet, still
 *                doesn't recover the selected variables of the selected experiment.
 *          04, April 2009
 *                Version v0.4a.07. The experiment repetition finctionality is complete, yet, there are some SVM configurations that have to be treated
 *                for proper saving. As usual, there are code improvements and bug corrections.
 *          07, April 2009
 *                Version v0.4a.08. The experiment repetition funcionality was improved, with all the bugs above mentioned corrected, yet there is a bug
 *                that displays the SaveExperiment frame several times for a single experiment.
 *          07, April 2009
 *                version v0.4a.09. The SaveExperiment was corrected, but this correction discovered that the code needs some improvements; this version is a
 *                checkpoint in order to be able to step back if something goes wrong (the improvements are tricky).
 *          09, April 2009
 *                Version v0.5a.00. First version that tryes to implement the optimization functionality.
 *          15, September 2009
 *                Version v0.5a.01. Portfolio revamp, minor string changes and dummy IpcButton class inclusion.
 *          16, October, 2009
 *                Version v0.5a.02. Classes ExcludeColumns, ExcludeTables, InputAttribs, TimeLine and StockExperiments normalized in order to allow the 
 *                creation of an abstract class AttributeFabric; that will allow to be conformant with design pattern method.
 *          29, October, 2009
 *                Version v0.5a.03 The project DB now includes tables for Risk Free and Stock Index as definitions for Optional parameters, that will be
 *                the foundation for the integration of a portfolio DB as part of a project. This version includes many optimizations on the Database and 
 *                Project clases.
 *                Note: the modifications introduced an error that manifests itself when an experiment is retrieved for reproduction on the SVM, it is evident
 *                on the Cost argument of the SVM.
 *          2, February, 2010
 *                Version v0.5a.04, new year revamp of v0.5a.03, with modifications to the classes: ProjectTreeTab and DBTreeTab that handle the display of database tree nodes.
 *                these classes are modified in order to comply better with pattern design, and now are based on the abstract class TreeTab.
 *                Note: the modifications introduced an error that manifests itself when an experiment is retrieved for reproduction on the SVM, it is evident
 *                on the Cost argument of the SVM.
 *                Note: once selected a project, it is not posible to switch to other one, unless leaving the app.
 *          1, April 2011;
 *                In order to implement support for multiple SQL DB implementations and,
 *                this class was changed to abstrat. the intention is to implement a factory pattern for such suppoort; the pattern implementation began with the refactoring
 *                ot the Column class.
 *          8, November, 2011
 *                Security version 0.5a.05
 *         18, November, 2011,
 *                The DB tree secction was updated to use factories all along, in order to facilitate the connection to different DBs.
 *         24  February 2014
 *                Sources reinstalled on a Linux server, some minor changes
 * 
 */


package portfolio;

import java.awt.*;
import java.net.URL;
import java.sql.*;
import java.util.Calendar;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;
import portfolio.dbHost.ConfigNew;
import portfolio.dbHost.Host;
import portfolio.dbHost.HostFactory;
import portfolio.dbHost.ProjectNew;
import portfolio.menu.StockItems;



public class mainScreen extends JFrame {
    private Host               dbLoggedHost       = null;
    private StockItems         stockItems         = null;
    private URL                urlIconLocation    = null;

    private String              sOsSeparator      = "\\";
    
    private final String        ICON_LOGO_PATH            = "Images/logoIcon.gif";
    private final String        INFO_VERSION              = "v0.5a.05";
    private final String        INFO_MSG_WELCOME          = "Portfolio tool " + INFO_VERSION;
    private final String        INFO_MSG_LOGGED_ON        = "Already logged on.";
    private final String        INFO_MSG_NOT_LOGGED_ON_DB = "Not logged on yet.";
    private final String        INGO_MSG_LOGGED_OFF       = "Logged off from database.";
    private final String        INFO_MSG_NO_DB_CONNECTION = "No connection with the DB established yet.";
    private final String        INFO_MSG_NO_DBS_AVAILABLE = "No databases available.";
    
    private final String        TITLE_MAIN                = "Portfolio Tool.";
    
//   Try to redirect stderr to JTestArea
//   http://www.ureader.de/msg/123016157.aspx
//   http://unserializableone.blogspot.com/2009/01/redirecting-systemout-and-systemerr-to.html 
//   http://forums.sun.com/thread.jspa?threadID=708960    
//    
//    private static class TextAreaPrintStream extends PrintStream {
//        private JTextArea consoleTextArea;
// 
//        TextAreaPrintStream(JTextArea consoleTextArea) {
//            //super (jta);
//            this.consoleTextArea = consoleTextArea;
//        }
//        /**
//         * 
//         * @Override
//         * 
//         */
//        public void println(String s) {
//            consoleTextArea.append(s + '/n');
//        }
// 
//        //override other PrintStream methods you want to support in the same fashion
//    }
//        
    /** Creates new form mainScreen */
    public mainScreen() {
        super ();
        this.setTitle (this.TITLE_MAIN);

        String sOperatingSystem = System.getProperty ("os.name") ;
        
        try {
            if (sOperatingSystem.equals("Windows XP")) {
                UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
            }
        } catch (Exception e) {
            this.displayMessage("mainScreen 146",e.toString());
        }        
        
        //make sure to get the icon from the jarfile 

        ClassLoader loader =  this.getClass ().getClassLoader();
        urlIconLocation = loader.getResource(this.ICON_LOGO_PATH);
        
        if (urlIconLocation != null) {
            ImageIcon logoIcon = new ImageIcon (urlIconLocation);
            super.setIconImage(logoIcon.getImage());
        } else {
/*0j0*/     System.out.println ("can't read icon logo."); //Warning: do not change for a graphic display; up to this point, the gui is not ready yet.
        }

	Dimension d = Toolkit.getDefaultToolkit ().getScreenSize ();
	setSize (d.width, (d.height*3)/4);
        
        this.initComponents();
        this.displayMessage("mainScreen 172", this.INFO_MSG_WELCOME);

    } /* end constructor mainScreen */
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSeparator1 = new javax.swing.JSeparator();
        jSplitPane1 = new javax.swing.JSplitPane();
        jPanel1 = new javax.swing.JPanel();
        jSplitPane2 = new javax.swing.JSplitPane();
        jTPaneLeft = new javax.swing.JTabbedPane();
        //ACA PreCode
        jDBasePanel = new javax.swing.JPanel();
        //new portfolio.portfolioDB.jDBaseTree(jDBasePanel);
        jProjectPanel = new javax.swing.JPanel();
        jPanelRight = new javax.swing.JPanel();
        jGeneralTab = new javax.swing.JTabbedPane();
        jPanelStocks = new javax.swing.JPanel();
        jTabbedPane2 = new javax.swing.JTabbedPane();
        jSelectVariablesTab = new javax.swing.JPanel();
        jSVMParamsTab = new javax.swing.JPanel();
        jPlotTab = new javax.swing.JPanel();
        jResultsTab = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jPanelOptimize = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jta = new javax.swing.JTextArea();
        jMenuBar = new javax.swing.JMenuBar();
        mFile = new javax.swing.JMenu();
        jMenuLogOnDB = new javax.swing.JMenuItem();
        jMenuLogOffDB = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        jMenuLoadSQL = new javax.swing.JMenuItem();
        jMenuSaveSQL = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        jMenuConfigure = new javax.swing.JMenuItem();
        jSeparator5 = new javax.swing.JSeparator();
        jMenuNewProj = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JSeparator();
        jMenuExit = new javax.swing.JMenuItem();
        /* Pre creation code */
        mStocks = new JMenu (); /* custom creation code */
        ;
        /* post creation code */
        stockItems = new StockItems (this, mStocks);
        mHelp = new javax.swing.JMenu();
        jMenuAbout = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jSplitPane1.setDividerLocation(400);
        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);

        jSplitPane2.setDividerLocation(150);

        jTPaneLeft.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);

        org.jdesktop.layout.GroupLayout jDBasePanelLayout = new org.jdesktop.layout.GroupLayout(jDBasePanel);
        jDBasePanel.setLayout(jDBasePanelLayout);
        jDBasePanelLayout.setHorizontalGroup(
            jDBasePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 144, Short.MAX_VALUE)
        );
        jDBasePanelLayout.setVerticalGroup(
            jDBasePanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 369, Short.MAX_VALUE)
        );

        jTPaneLeft.addTab("DBase", jDBasePanel);

        org.jdesktop.layout.GroupLayout jProjectPanelLayout = new org.jdesktop.layout.GroupLayout(jProjectPanel);
        jProjectPanel.setLayout(jProjectPanelLayout);
        jProjectPanelLayout.setHorizontalGroup(
            jProjectPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 144, Short.MAX_VALUE)
        );
        jProjectPanelLayout.setVerticalGroup(
            jProjectPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 369, Short.MAX_VALUE)
        );

        jTPaneLeft.addTab("Project", jProjectPanel);

        jSplitPane2.setLeftComponent(jTPaneLeft);

        jPanelRight.setLayout(new java.awt.BorderLayout());

        jPanelStocks.setLayout(new java.awt.BorderLayout());

        org.jdesktop.layout.GroupLayout jSelectVariablesTabLayout = new org.jdesktop.layout.GroupLayout(jSelectVariablesTab);
        jSelectVariablesTab.setLayout(jSelectVariablesTabLayout);
        jSelectVariablesTabLayout.setHorizontalGroup(
            jSelectVariablesTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 617, Short.MAX_VALUE)
        );
        jSelectVariablesTabLayout.setVerticalGroup(
            jSelectVariablesTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 331, Short.MAX_VALUE)
        );

        jTabbedPane2.addTab("Select Variables", jSelectVariablesTab);

        org.jdesktop.layout.GroupLayout jSVMParamsTabLayout = new org.jdesktop.layout.GroupLayout(jSVMParamsTab);
        jSVMParamsTab.setLayout(jSVMParamsTabLayout);
        jSVMParamsTabLayout.setHorizontalGroup(
            jSVMParamsTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 617, Short.MAX_VALUE)
        );
        jSVMParamsTabLayout.setVerticalGroup(
            jSVMParamsTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 331, Short.MAX_VALUE)
        );

        jTabbedPane2.addTab("SVM Params", jSVMParamsTab);

        org.jdesktop.layout.GroupLayout jPlotTabLayout = new org.jdesktop.layout.GroupLayout(jPlotTab);
        jPlotTab.setLayout(jPlotTabLayout);
        jPlotTabLayout.setHorizontalGroup(
            jPlotTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 617, Short.MAX_VALUE)
        );
        jPlotTabLayout.setVerticalGroup(
            jPlotTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 331, Short.MAX_VALUE)
        );

        jTabbedPane2.addTab("Plot", jPlotTab);

        org.jdesktop.layout.GroupLayout jResultsTabLayout = new org.jdesktop.layout.GroupLayout(jResultsTab);
        jResultsTab.setLayout(jResultsTabLayout);
        jResultsTabLayout.setHorizontalGroup(
            jResultsTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 617, Short.MAX_VALUE)
        );
        jResultsTabLayout.setVerticalGroup(
            jResultsTabLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 331, Short.MAX_VALUE)
        );

        jTabbedPane2.addTab("Results", jResultsTab);

        jPanelStocks.add(jTabbedPane2, java.awt.BorderLayout.CENTER);
        jPanelStocks.add(jPanel4, java.awt.BorderLayout.PAGE_START);

        jGeneralTab.addTab("Stocks", jPanelStocks);
        jPanelStocks.getAccessibleContext().setAccessibleParent(jPanelRight);

        org.jdesktop.layout.GroupLayout jPanelOptimizeLayout = new org.jdesktop.layout.GroupLayout(jPanelOptimize);
        jPanelOptimize.setLayout(jPanelOptimizeLayout);
        jPanelOptimizeLayout.setHorizontalGroup(
            jPanelOptimizeLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 622, Short.MAX_VALUE)
        );
        jPanelOptimizeLayout.setVerticalGroup(
            jPanelOptimizeLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 369, Short.MAX_VALUE)
        );

        jGeneralTab.addTab("Optimize", jPanelOptimize);

        jPanelRight.add(jGeneralTab, java.awt.BorderLayout.CENTER);

        jSplitPane2.setRightComponent(jPanelRight);

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jSplitPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 783, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jSplitPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 399, Short.MAX_VALUE)
        );

        jSplitPane1.setTopComponent(jPanel1);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Output"));

        jta.setColumns(20);
        jta.setEditable(false);
        jta.setRows(5);
        jScrollPane1.setViewportView(jta);

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 767, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );

        jSplitPane1.setRightComponent(jPanel2);

        mFile.setText("File");
        mFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mFileActionPerformed(evt);
            }
        });

        jMenuLogOnDB.setText("Log on DB");
        jMenuLogOnDB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuLogOnDBActionPerformed(evt);
            }
        });
        mFile.add(jMenuLogOnDB);
        jMenuLogOnDB.getAccessibleContext().setAccessibleName("logon DB");

        jMenuLogOffDB.setText("Log off ");
        jMenuLogOffDB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuLogOffDBActionPerformed(evt);
            }
        });
        mFile.add(jMenuLogOffDB);
        mFile.add(jSeparator2);

        jMenuLoadSQL.setText("Load SQL file");
        jMenuLoadSQL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuLoadSQLActionPerformed(evt);
            }
        });
        mFile.add(jMenuLoadSQL);

        jMenuSaveSQL.setText("Save DB to file");
        jMenuSaveSQL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuSaveSQLActionPerformed(evt);
            }
        });
        mFile.add(jMenuSaveSQL);
        mFile.add(jSeparator3);

        jMenuConfigure.setText("Configure");
        jMenuConfigure.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuConfigureActionPerformed(evt);
            }
        });
        mFile.add(jMenuConfigure);
        mFile.add(jSeparator5);

        jMenuNewProj.setText("Project");
        jMenuNewProj.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuNewProjActionPerformed(evt);
            }
        });
        mFile.add(jMenuNewProj);
        mFile.add(jSeparator4);

        jMenuExit.setText("Exit");
        jMenuExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuExitActionPerformed(evt);
            }
        });
        mFile.add(jMenuExit);

        jMenuBar.add(mFile);

        /* pre init code */
        mStocks.setText("Stocks");
        /* post init code */
        mStocks.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mStocksActionPerformed(evt);
            }
        });
        jMenuBar.add(mStocks);

        mHelp.setText("Help");

        jMenuAbout.setText("About");
        mHelp.add(jMenuAbout);

        jMenuBar.add(mHelp);

        setJMenuBar(jMenuBar);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 785, Short.MAX_VALUE)
            .add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 785, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 22, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSplitPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 421, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuConfigureActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuConfigureActionPerformed
// TODO add your handling code here:
        try {
            new ConfigNew (this);
        } catch (Exception ex) {
            this.displayMessage("mainScreen.jMenuConfigureActionPerformed 490", ex.toString());
        }
    }//GEN-LAST:event_jMenuConfigureActionPerformed

    private void jMenuLogOffDBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuLogOffDBActionPerformed
// TODO add your handling code here:
        try {
            if (dbLoggedHost == null) {
                this.displayMessage ("mainScreen.jMenuLogOffDBActionPerformed 498", this.INFO_MSG_NOT_LOGGED_ON_DB);
                return;
            }  else if (dbLoggedHost.getConnection() == null) {
                this.displayMessage ("mainScreen.jMenuLogOffDBActionPerformed 501", this.INFO_MSG_NOT_LOGGED_ON_DB);
            }  else {
                this.displayMessage ("mainScreen.jMenuLogOffDBActionPerformed 503", this.INGO_MSG_LOGGED_OFF);
            }        
            dbLoggedHost.shutDown();
            dbLoggedHost = null;
            jDBasePanel.removeAll ();
            jProjectPanel.removeAll();
            //this.displayMessage (this.INGO_MSG_LOGGED_OFF);
        } catch (Exception ex) {
            StackTraceElement stackTrace = ex.getCause().getStackTrace()[0];
            this.displayErrorMsg (stackTrace, ex.toString());
        }
    }//GEN-LAST:event_jMenuLogOffDBActionPerformed

    private void jMenuExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuExitActionPerformed
        try {
            if (dbLoggedHost == null) {
/*0j0*/         System.err.println(this.INFO_MSG_NOT_LOGGED_ON_DB);
                System.exit (0);
            }
            dbLoggedHost.shutDown();
        }
        catch (Exception exp) {
/*0j0*/     System.err.println (exp);
            System.exit (1);
        }
        System.exit (0);                
    }//GEN-LAST:event_jMenuExitActionPerformed

    private void jMenuLoadSQLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuLoadSQLActionPerformed
//        String sActionCommand = evt.getActionCommand();

        if (dbLoggedHost == null) {
            StackTraceElement stackElement = (new Throwable()).getStackTrace() [0];
            this.displayErrorMsg(stackElement, this.INFO_MSG_NOT_LOGGED_ON_DB);
            return;
        }
        
        Connection connection = dbLoggedHost.getConnection ();   // << ??????
        if (connection == null) {
            this.displayMessage("mainScreen.jMenuLoadSQLActionPerformed 544", this.INFO_MSG_NO_DB_CONNECTION);
            return;
        }
        LoadSqlDB loadSqlDb = new LoadSqlDB (this);               
        
    }//GEN-LAST:event_jMenuLoadSQLActionPerformed

    private void jMenuSaveSQLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuSaveSQLActionPerformed
        try {
            if (dbLoggedHost == null) {
                this.displayMessage("mainScreen.jMenuSaveSQLActionPerformed 554", this.INFO_MSG_NOT_LOGGED_ON_DB);
                return;
            }
            
            Vector vDataBases = dbLoggedHost.showDBs();
            if (vDataBases.size() > 0) {
                new portfolio.SaveSqlDB (this, null, vDataBases, sOsSeparator).setVisible(true);
            } else {
                this.displayMessage ("mainScreen.jMenuSaveSQLActionPerformed 567", this.INFO_MSG_NO_DBS_AVAILABLE);
            }
            
        } catch (Exception ex) {
            this.displayMessage ("mainScreen.jMenuSaveSQLActionPerformed 571", ex.toString());
        }        
    }//GEN-LAST:event_jMenuSaveSQLActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
// TODO add your handling code here:
        try {
            if (dbLoggedHost == null) {
                System.exit (0);
            }
            dbLoggedHost.shutDown();
        }
        catch (Exception exp) {
/*0j0*/     System.err.println (exp);
        }
        System.exit (0);        
    }//GEN-LAST:event_formWindowClosing

    private void jMenuNewProjActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuNewProjActionPerformed
// TODO add your handling code here:
        try {
            if (dbLoggedHost != null) {
                Vector vDataBases = dbLoggedHost.showDBs();

                if (vDataBases.size() > 0) {
                    new ProjectNew (dbLoggedHost).setVisible(true);
//                    System.out.println ("0j0 >>>>>>>>>>>>>>>>>> WARNING: due to mintennce, NewProject was not created.");
//                    this.displayMessage("656", "0j0 >>>>>>>>>>>>>>>>>> WARNING: due to mintennce, NewProject was not created.");
                } else {
                    this.displayMessage ("MainScreen.jMenuNewProjActionPerformed 602", this.INFO_MSG_NO_DBS_AVAILABLE);
                }
            } else {
                this.displayMessage ("MainScreen.jMenuNewProjActionPerformed 605", this.INFO_MSG_NOT_LOGGED_ON_DB);
            }
        } catch (Exception ex) {
            StackTraceElement stackElement = (new Throwable()).getStackTrace() [0];
            this.displayErrorMsg (stackElement, ex.toString());        
        }        
    }//GEN-LAST:event_jMenuNewProjActionPerformed

    private void jMenuLogOnDBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuLogOnDBActionPerformed
// TODO add your handling code here:

        try {
//            HostFactory hostFactory = 
            if (this.getDBLoggedHost() == null) {
                new HostFactory (this);
            } else {
                this.displayMessage("MainScreen.jMenuLogOnDBActionPerformed 680", "Log off previous DB session.");
            }
//            if (dbLoggedHost == null) {
//                hostFactory.getHostType();
////                dbLoggedHost = new OdbcHost (this);
//            } else {
//                if (dbLoggedHost.getConnection() == null) {
//                    hostFactory.getHostType();
////                    dbLoggedHost = new OdbcHost (this);
//                } else {
//                    this.displayMessage("MainScreen.jMenuLogOnDBActionPerformed 624", INFO_MSG_LOGGED_ON);
//                }
//            }
        } catch (Exception ex) {
             this.displayMessage("MainScreen.jMenuLogOnDBActionPerformed 628", ex.toString());
        }
    }//GEN-LAST:event_jMenuLogOnDBActionPerformed

    private void mStocksActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mStocksActionPerformed
// TODO add your handling code here:
        
    }//GEN-LAST:event_mStocksActionPerformed

    private void mFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mFileActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_mFileActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new mainScreen().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jDBasePanel;
    private javax.swing.JTabbedPane jGeneralTab;
    private javax.swing.JMenuItem jMenuAbout;
    private javax.swing.JMenuBar jMenuBar;
    private javax.swing.JMenuItem jMenuConfigure;
    private javax.swing.JMenuItem jMenuExit;
    private javax.swing.JMenuItem jMenuLoadSQL;
    private javax.swing.JMenuItem jMenuLogOffDB;
    private javax.swing.JMenuItem jMenuLogOnDB;
    private javax.swing.JMenuItem jMenuNewProj;
    private javax.swing.JMenuItem jMenuSaveSQL;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanelOptimize;
    private javax.swing.JPanel jPanelRight;
    private javax.swing.JPanel jPanelStocks;
    private javax.swing.JPanel jPlotTab;
    private javax.swing.JPanel jProjectPanel;
    private javax.swing.JPanel jResultsTab;
    private javax.swing.JPanel jSVMParamsTab;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel jSelectVariablesTab;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JTabbedPane jTPaneLeft;
    private javax.swing.JTabbedPane jTabbedPane2;
    private javax.swing.JTextArea jta;
    private javax.swing.JMenu mFile;
    private javax.swing.JMenu mHelp;
    private javax.swing.JMenu mStocks;
    // End of variables declaration//GEN-END:variables
  /**
     *
     * @param stringMessage 
     */
//    public void displayMessage (String stringMessage)
//    {
//        java.util.Date dDate = Calendar.getInstance().getTime();
//
//        jta.append (dDate.toString() + "> " + stringMessage + "\n");
// 
//        return;
//    } /* end method displayMessage */
    public void displayMessage (String sLine, String stringMessage)
    {
        java.util.Date dDate = Calendar.getInstance().getTime();

        jta.append (dDate.toString() + " Place: " + sLine + "> " + stringMessage + "\n");
 
        return;
    } /* end method displayMessage */    /**
     *
     * @param stringMessage 
     */
    public void displayMessageNoCRLF (String stringMessage)
    {
        jta.append (stringMessage);
 
        return;
    } /* end method displayMessageNoCRLF */
    /**
     * usage:
     *     When no exception was produced:
     *      StackTraceElement stackTrace = (new Throwable()).getStackTrace()[0];
     *     When an exception was prodiced:
     *      StackTraceElement stackTrace = ex.getCause().getStackTrace()[0];
     * @param stackElementParam 
     * @param sErrMsgParam 
     */
    public void displayErrorMsg (StackTraceElement stackElementParam, String sErrMsgParam)
    {
        int iLine = stackElementParam.getLineNumber();
        String sClass = stackElementParam.getClassName();
        String sMethod = stackElementParam.getMethodName();
        
        String sErrMsg = "line: " + iLine + "; class: " + sClass + "; method: " + sMethod + "\n";
        sErrMsg = sErrMsg + sErrMsgParam;
        
        this.displayMessage(null, sErrMsg);
        
        return;
    }
    /**
     *
     *
     */
    public JPanel getProjectPanel ()
    {
        return jProjectPanel;
    }
    /**
     *
     */
    public JPanel getDBasePanel ()
    {
        return jDBasePanel;
    }
/**
 * ACA code
 * @return
 */
    public StockItems getStockItems ()
    {
        return stockItems;
    }
    /**
     *
     * @return 
     */
    public Host getDBLoggedHost ()
    {
        return dbLoggedHost;
    }
    /**
     *
     * @param dbasesHostParam 
     */
    public void setDBLoggedHost (Host dbasesHostParam)
    {
        dbLoggedHost = dbasesHostParam;
        return;
    }
    /**
     *
     * @return 
     */
    public String getSeparator ()
    {
        return sOsSeparator;
    }
    /**
     *
     * @return 
     */
    public JSplitPane getSplitPane2 ()
    {
        return jSplitPane2;
    }
    /**
     *
     * @return 
     */
    public JTabbedPane getJTpaneLeft ()
    {
        return jTPaneLeft;
    }
    /**
     *
     * @return 
     */
    public JMenu getMFile ()
    {
        return mFile;
    }
    /**
     *
     * @return 
     */
    public JPanel getSelectVariablesPanel ()
    {
        return jSelectVariablesTab;
    }
    /**
     *
     * @return 
     */
    public JPanel getSVMParamsPanel ()
    {
        return jSVMParamsTab;
    }
    /**
     *
     * @return 
     */
    public JPanel getPlotPanel ()
    {
        return jPlotTab;
    }
    /**
     *
     * @return 
     */
    public JPanel getResultsPanel ()
    {
        return jResultsTab;
    }
    /**
     *
     * @return 
     */
    public JPanel getPrjNewTab ()
    {
        return jProjectPanel;
    }
    /**
     * 
     * @return 
     */
    public URL getURLIconLogo ()
    {
        return urlIconLocation;
        
    }
    /**
     * 
     * @return 
     */
    public JTabbedPane getRightTabbedPanel ()
    {
        return jTabbedPane2;
    }
    /**
     * 
     */
    public void repaintStockTabedPanels ()
    {

        JPanel jResultsPanel = this.getResultsPanel();
        jResultsPanel.removeAll();
        jResultsPanel.repaint();
        JPanel jPlotPanel = this.getPlotPanel();
        jPlotPanel.removeAll();
        jPlotPanel.repaint();
        JPanel jSVMPanel = this.getSVMParamsPanel();
        jSVMPanel.removeAll();
        jSVMPanel.repaint();
        JPanel jVariablesPanel = this.getSelectVariablesPanel();
        jVariablesPanel.removeAll();
        jVariablesPanel.repaint();
        
        jTabbedPane2.setSelectedComponent(jVariablesPanel);
    }
} /* end class mainScreen */
